import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { useUserStore } from '@/store/modules/user'
import * as datarApi from "@/api/data";
import { TableColumn } from '@/types/table'
const getUserInfo = useUserStore().getUserInfo;
const flag = getUserInfo.roles.some(item=>item.name=='超级管理员'||item.name=='国家级管理员'||item.name=='国家级业务人员') 
const cityList = await datarApi.cityList();

const categoryOpt = ref([
  {label:'圆模型',value:'1'},
  {label:'椭圆模型',value:'2'},
  {label:'线源模型',value:'3'},
  ])
// 表单校验
export const rules = reactive({
  category: [{ required: true, message: '模型类别不能为空', trigger: 'change' }],
  type: [{ required: true, message: '数据类型不能为空', trigger: 'change' }],
  modelName: [{ required: true, message: '模型名称不能为空', trigger: 'blur' }],
  userName: [{ required: true, message: '维护人不能为空', trigger: 'blur' }],
  deptName: [{ required: true, message: '维护人单位不能为空', trigger: 'blur' }],
})

// CrudSchema：https://doc.iocoder.cn/vue3/crud-schema/
const crudSchemas = reactive<CrudSchema[]>([
  {
    field: 'index',
    label: '序号',
    type: 'index',
    isForm: false,
    isDetail: false
},
{
  label: '维护人所属单位',
  field: 'divisionCode',
  width: '200px',
  formatter: (_: Recordable, __: TableColumn, cellValue: number) => {
    return cityList.find((account) => account.id === cellValue)?.mail
  },
  search: {
    show: true,
    component: 'Select',
    api: () => cityList,
    componentProps: {
      optionsAlias: {
        labelField: 'divisionName',
        valueField: 'divisionCode'
      }
    }
  },
  isForm: false,
  isTable:false,
},
{
  field: 'modelName',
  label:'模型名称',
  isSearch: true,
  minWidth: 200,
},
{
  field: 'category',
  label:'模型类别',
  isSearch: true,
  search: {
    component: 'Select',
    componentProps: {
      options: categoryOpt.value,
      optionsAlias: {
        labelField: 'label',
        valueField: 'value'
      }
    }
  },
  width: '200px',
},
{
  field: 'type',
  label:'数据类型',
  with:'',
},
{
  field: 'userName',
  label:'维护人',
  with:'',
},
{
  field: 'deptName',
  label:'维护人所属单位',
  with:'',
},
  {
    label: '操作',
    field: 'action',
    isForm: false,
    isDetail: false
  }
])
export const { allSchemas } = useCrudSchemas(crudSchemas)
